local weilin = fk.CreateSkill({
  name = "kq__weilin",
})

weilin:addEffect(fk.EventPhaseProceeding, {
  anim_type = "support",
  prompt = "威临：将手牌数摸至恰为全场唯一最多",
  can_trigger = function(self, event, target, player, data)
    local n = 0
    for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p:getHandcardNum() > n then
          n = p:getHandcardNum()
        end
    end
    return player:hasSkill(weilin.name) and target.phase == Player.Start and target == player
    and player:getHandcardNum() <= n
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p:getHandcardNum() > n then
          n = p:getHandcardNum()
        end
    end
    local num = n-player:getHandcardNum()+1
    player:drawCards(num , weilin.name)
    local choice = room:askToChoice(player, {
        choices = {"本回合你的红色手牌视为基础伤害为2的【杀】" , "本回合你的黑色手牌视为使用时无距离限制的【杀】"},
        skill_name = weilin.name
    })
    if choice == "本回合你的红色手牌视为基础伤害为2的【杀】" then
        room:addPlayerMark(player, "@@kq__weilin__red-turn")

    elseif choice == "本回合你的黑色手牌视为使用时无距离限制的【杀】" then
        room:addPlayerMark(player, "@@kq__weilin__black-turn")

    end
  end
})

weilin:addEffect("filter", {
  card_filter = function(self, to_select, player, is_judge)
    return (to_select.suit == Card.Heart or to_select.suit == Card.Diamond)
    and player:hasSkill(weilin.name) and
    (table.contains(player:getCardIds("h"), to_select.id) or is_judge) and
      player:getMark("@@kq__weilin__red-turn") ~= 0
  end,
  view_as = function(self, player, to_select)
    return Fk:cloneCard("slash", to_select.suit, to_select.number)
  end,
})

weilin:addEffect("filter", {
  card_filter = function(self, to_select, player, is_judge)
    return (to_select.suit == Card.Spade or to_select.suit == Card.Club)
    and player:hasSkill(weilin.name) and
    (table.contains(player:getCardIds("h"), to_select.id) or is_judge) and
      player:getMark("@@kq__weilin__black-turn") ~= 0
  end,
  view_as = function(self, player, to_select)
    return Fk:cloneCard("slash", to_select.suit, to_select.number)
  end,
})

weilin:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card and player:getMark("@@kq__weilin__red-turn") ~= 0
    and data.to and data.card.color == Card.Red
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
      data:changeDamage(1)
  end,
})

weilin:addEffect("targetmod", {
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill(weilin.name) and card.color == Card.Black and player:getMark("@@kq__weilin__black-turn") ~= 0
  end,
})

Fk:loadTranslationTable {
["kq__weilin"] = "威临",
[":kq__weilin"] = "准备阶段，你可以将手牌数摸至恰为全场唯一最多（至少摸一张牌），然后你扶择：本回合你的红色手牌视为基础伤害为2的【杀】；本回合你的黑色手牌视为使用时无距离限制的【杀】。",
["$kq__weilin1"] = "",
["$kq__weilin2"] = "",
["@@kq__weilin__red-turn"] = "威临 <font color='red'>红</font>",
["@@kq__weilin__black-turn"] = "威临 黑",
}
return weilin